<?php

namespace App\Http\Controllers;

use App\Models\Admin;
use App\Models\Statistics;
use Illuminate\Http\Request;

class WelcomeController extends Controller
{



    public function login()
    {

//        return md5(md5(123456));

        return  view('login');
    }

    public function loginVerify(Request $request)
    {

        $this->validate($request, [
            'username'      => 'required',
            'password'      => 'required',
        ]);


        $params['username'] =   $request->input('username');
        $params['password'] =   md5(md5($request->input('password')));


        $res = Admin::where($params)->first();

        if ($res)
        {
            session(['id' => $res->id]);

            return redirect(url('/'));

        }else{
            return redirect(url('login'))->withErrors(['账号密码错误'])->withInput();
        }


    }

    public function index(Statistics $statistics)
    {
        $data['listing'] = $statistics->orderBy('id' , 'DESC')->paginate(50);

        return view('welcome' , $data);


    }
}
